#ifndef __STDMYSQL_
#define __STDMYSQL_
#include <string>
#include <vector>
#include <memory>

#define MYSQLPOOL stdMysqlPool::GlobalInstance()  

struct stdMysqlPrivate;
using CStrRef = const std::string&;
using StrArray = std::vector<std::string>;
class stdMysql
{
public:
    stdMysql();
    ~stdMysql();
    bool Connect(CStrRef host, CStrRef user, CStrRef passwd, CStrRef databaseName, unsigned int port = 3306);
    bool IsConnected();
    bool Execute(CStrRef sql);
    bool ExecuteTransaction(const StrArray& sqlVec);
    std::vector<StrArray> GetTableInfo(CStrRef sql);
private:
    stdMysqlPrivate* p;
};

using MysqlPtr = std::shared_ptr<stdMysql>;

//连接池
struct stdMysqlPoolPrivate;
class stdMysqlPool
{
public:
    static stdMysqlPool* GlobalInstance();
    bool SetParams(int MaxCount, CStrRef host, CStrRef user, CStrRef passwd, CStrRef databaseName, unsigned int port = 3306);
    MysqlPtr GetMysql();//取连接
    void CloseMysql(MysqlPtr ptr);
    ~stdMysqlPool();
private:
    stdMysqlPool();//单例模式
    stdMysqlPoolPrivate *p;
};

#endif